/**
 * 项目名：化工企业安全生产信息化管理平台
 * 日期：    2020-03-01 22:19:08
 * Copyright (c) 2015- -版权所有
 */

package com.joysuch.wwyt.edu.repository;

import com.joysuch.wwyt.edu.entity.EduQuestion;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;

import java.util.List;

/**
 * EduQuestionDao
 *
 */
public interface EduQuestionDao extends JpaRepository<EduQuestion, Long>, QuerydslPredicateExecutor<EduQuestion> {
    public Page<EduQuestion> findAll(Specification<EduQuestion> spec, Pageable pageable);

    public EduQuestion save(EduQuestion bean);

    public void delete(EduQuestion bean);

    @Query("select count(m) from EduQuestion m where code = ?1")
    long countOfCode(String code);

    @Query("from EduQuestion where code = ?1 and deleteFlag = '0'")
    EduQuestion selectByCode(String code);

    @Query("select count(m) from EduQuestion m where code = ?1 and id != ?2")
    long countOfCodeExcludeId(String code, Long id);

    List<EduQuestion> findByTypeAndNameAndQuestionTypeId(String questionType, String name, Long id);

    @Query("select eq from EduQuestion eq where eq.deleteFlag = '0' and eq.id in (?1)")
    List<EduQuestion> findByIds(List<Long> ids);
}
